
namespace Needle.Core.Lifetime {

    /// <summary>
    /// Tracks an instance forever.
    /// </summary>
    /// <remarks>
    /// This trackingpolicy is not named Singleton because it is very much possible 
    /// to track multiple instances of the same type with this policy.
    /// </remarks>
    public class PermanentAttribute : TrackingPolicyAttribute {

        /// <summary>
        /// Applies the permanent tracking policy to the instance.
        /// </summary>
        public override IReference Apply(object instance) {
            return new PermanentReference(instance);
        }

        private class PermanentReference : IReference {

            object instance;
            public PermanentReference(object instance) {
                this.instance = instance;
            }
            #region IReference Members

            public object Target {
                get { return instance; }
            }

            public bool IsValid {
                get { return true; }
            }

            #endregion
        }
    }
}
